package com.boot2523.service;


import com.boot2523.bean.Order;
import com.boot2523.common.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

@Service
public class OrderProducer {

    private final RabbitTemplate rabbitTemplate;//提供发送消息的模板类
    private final String exchangeName;
    private final String routingKey;

//    @Autowired
    public OrderProducer(RabbitTemplate rabbitTemplate, RabbitMQConfig config) {
        this.rabbitTemplate = rabbitTemplate;
        this.exchangeName = config.EXCHANGE_NAME;
        this.routingKey = "order.new"; // 路由键
    }

    public void sendOrder(Order order) {
        System.out.println("Sending order: " + order);
        rabbitTemplate.convertAndSend(exchangeName, routingKey, order);
    }
}
